package com.appwoo.txtws.activity;

import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Resources;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.view.Display;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import com.appwoo.android.exception.NotFoundNetWorkException;
import com.appwoo.android.exception.TimeOutException;
import com.appwoo.txtws.adapter.WallpaperListAdapter;
import com.appwoo.txtws.app.AppActivity;
import com.appwoo.txtws.bean.WallpaperBean;
import com.appwoo.txtws.component.DBHelper;
import com.appwoo.txtws.component.Global;
import com.appwoo.txtws.component.Logger;
import com.appwoo.txtws.service.WallpaperService;
import com.appwoo.txtws.wheel.widget.PageListView;
import com.appwoo.txtws.wheel.widget.PageListView.OnRefreshListener;
import java.io.IOException;
import java.util.ArrayList;
import org.xmlpull.v1.XmlPullParserException;

public class WallpaperListActivity extends AppActivity
  implements AbsListView.OnScrollListener
{
  public static final String SP_KEY_WALLPAPER = "wallpaper";
  public static final String SP_KEY_WALLPAPER_WIRTE = "wallpaperWrite";
  private boolean blDataTask = false;
  private boolean dbClientHaveMore = true;
  private boolean dbServerHaveMore = true;
  private Boolean isFoot = Boolean.valueOf(false);
  private ArrayList<WallpaperBean> listWallpaperBean = null;
  private PageListView lvList;
  private WallpaperListAdapter mAdapter;
  private DBHelper mDBHelper;
  private int pageClient = 0;
  private int pageServer = 1;
  private int pageSize = 6;

  private boolean existSDCard()
  {
    return Environment.getExternalStorageState().equals("mounted");
  }

  private void findView()
  {
    this.lvList = ((PageListView)findViewById(2131492985));
  }

  private ArrayList<WallpaperBean> getWebWallpaper(int paramInt1, int paramInt2)
  {
    ArrayList localArrayList1 = new ArrayList();
    WallpaperService localWallpaperService = new WallpaperService();
    try
    {
      int i = this.mDBHelper.getWebWallpaperIdMax();
      ArrayList localArrayList2 = localWallpaperService.getWebWallpaperListInfo(this, Global.USERNAME, i, paramInt1, paramInt2);
      return localArrayList2;
    }
    catch (IOException localIOException)
    {
      Logger.e("EXCEPTION", localIOException.getMessage());
      return localArrayList1;
    }
    catch (XmlPullParserException localXmlPullParserException)
    {
      Logger.e("EXCEPTION", localXmlPullParserException.getMessage());
      return localArrayList1;
    }
    catch (TimeOutException localTimeOutException)
    {
      Logger.e("EXCEPTION", localTimeOutException.getMessage());
      return localArrayList1;
    }
    catch (NotFoundNetWorkException localNotFoundNetWorkException)
    {
      Logger.e("EXCEPTION", localNotFoundNetWorkException.getMessage());
    }
    return localArrayList1;
  }

  private void initActionBar()
  {
    hideBarHome();
    setBarTitle(getResources().getString(2131427431));
    setBarBackOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        WallpaperListActivity.this.finish();
      }
    });
  }

  private void loadingData()
  {
    if ((!this.dbClientHaveMore) && (this.dbServerHaveMore))
    {
      if (!isNetworkAvailable(this))
      {
        alertMessage(getString(2131428051));
        closeProgress();
        this.lvList.onLoadMoreComplete();
        this.blDataTask = true;
        return;
      }
      if (((!Global.isSDCard()) || (Global.getSDCardSize(this) < 30)) && (Global.getMemorySize() < 30))
      {
        alertMessage(getString(2131427437));
        closeProgress();
        this.lvList.onLoadMoreComplete();
        this.blDataTask = true;
        return;
      }
    }
    this.mAdapter.tipWallpaperDownloadFail = false;
    this.mAdapter.tipNotNet = false;
    this.mAdapter.tipStorageSize = false;
    addOperation(new DataTask().execute(new String[0]));
  }

  private void setView()
  {
    wirteAppInnerWallpaperData();
    ArrayList localArrayList = new ArrayList();
    Display localDisplay = getWindowManager().getDefaultDisplay();
    this.mAdapter = new WallpaperListAdapter(this, localArrayList, "", 2, localDisplay.getWidth(), localDisplay.getHeight());
    this.lvList.setAdapter(this.mAdapter);
    this.lvList.setOnScrollListener(this);
    this.lvList.setOnLoadMoreListener(new PageListView.OnRefreshListener()
    {
      public void onRefresh()
      {
        if ((!WallpaperListActivity.this.lvList.getIsNoMore()) && (WallpaperListActivity.this.blDataTask))
        {
          WallpaperListActivity.this.lvList.prepareForRefreshMore();
          WallpaperListActivity.this.isFoot = Boolean.valueOf(true);
          WallpaperListActivity.this.loadingData();
        }
      }
    });
    loadingData();
  }

  private void wirteAppInnerWallpaperData()
  {
    SharedPreferences localSharedPreferences = getSharedPreferences("wallpaper", 0);
    ArrayList localArrayList;
    String[] arrayOfString;
    if (localSharedPreferences.getString("wallpaperWrite", null) == null)
    {
      localArrayList = new ArrayList();
      arrayOfString = getResources().getStringArray(2131165203);
    }
    for (int i = 0; ; i++)
    {
      if (i >= arrayOfString.length)
      {
        SharedPreferences.Editor localEditor = localSharedPreferences.edit();
        localEditor.putString("wallpaperWrite", "writed");
        localEditor.commit();
        return;
      }
      WallpaperBean localWallpaperBean = new WallpaperBean();
      localWallpaperBean.setName(arrayOfString[i]);
      localWallpaperBean.setType("appInner");
      localArrayList.add(localWallpaperBean);
      this.mDBHelper.updateWallpaper(localWallpaperBean);
    }
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903227);
    this.mDBHelper = new DBHelper(this);
    initActionBar();
    findView();
    setView();
  }

  protected void onDestroy()
  {
    super.onDestroy();
    this.mAdapter.gc();
  }

  public void onScroll(AbsListView paramAbsListView, int paramInt1, int paramInt2, int paramInt3)
  {
  }

  public void onScrollStateChanged(AbsListView paramAbsListView, int paramInt)
  {
    if ((paramInt == 0) && (paramAbsListView.getLastVisiblePosition() == -1 + paramAbsListView.getCount()) && (!this.lvList.getIsNoMore()) && (this.blDataTask))
    {
      this.lvList.prepareForRefreshMore();
      this.isFoot = Boolean.valueOf(true);
      loadingData();
    }
  }

  class DataTask extends AsyncTask<String, Integer, String>
  {
    DataTask()
    {
    }

    protected String doInBackground(String[] paramArrayOfString)
    {
      WallpaperListActivity.this.listWallpaperBean = new ArrayList();
      if (WallpaperListActivity.this.dbClientHaveMore)
        WallpaperListActivity.this.listWallpaperBean = WallpaperListActivity.this.mDBHelper.getWallpaperList(WallpaperListActivity.this.pageClient * WallpaperListActivity.this.pageSize, WallpaperListActivity.this.pageSize);
      while (true)
      {
        return null;
        if (WallpaperListActivity.this.dbServerHaveMore)
        {
          ArrayList localArrayList = WallpaperListActivity.this.getWebWallpaper(WallpaperListActivity.this.pageServer, WallpaperListActivity.this.pageSize);
          WallpaperListActivity.this.listWallpaperBean = WallpaperListActivity.this.mDBHelper.updateWallpaperList(localArrayList);
        }
      }
    }

    protected void onPostExecute(String paramString)
    {
      if ((WallpaperListActivity.this.dbClientHaveMore) && ((WallpaperListActivity.this.listWallpaperBean == null) || (WallpaperListActivity.this.listWallpaperBean.isEmpty())))
      {
        WallpaperListActivity.this.dbClientHaveMore = false;
        WallpaperListActivity.this.loadingData();
      }
      while (true)
      {
        super.onPostExecute(paramString);
        return;
        if ((WallpaperListActivity.this.dbServerHaveMore) && ((WallpaperListActivity.this.listWallpaperBean == null) || (WallpaperListActivity.this.listWallpaperBean.isEmpty())))
        {
          WallpaperListActivity.this.dbServerHaveMore = false;
          WallpaperListActivity.this.lvList.onLoadMoreComplete();
          WallpaperListActivity.this.blDataTask = true;
          WallpaperListActivity.this.lvList.hideFotterMoreView();
          WallpaperListActivity.this.lvList.setIsNoMore(true);
          if (!WallpaperListActivity.this.isFoot.booleanValue())
          {
            WallpaperListActivity.this.closeProgress();
            WallpaperListActivity.this.isFoot = Boolean.valueOf(false);
          }
        }
        else
        {
          if ((WallpaperListActivity.this.listWallpaperBean != null) || (!WallpaperListActivity.this.listWallpaperBean.isEmpty()))
          {
            if (WallpaperListActivity.this.dbClientHaveMore)
            {
              WallpaperListActivity localWallpaperListActivity2 = WallpaperListActivity.this;
              localWallpaperListActivity2.pageClient = (1 + localWallpaperListActivity2.pageClient);
            }
            while (true)
            {
              WallpaperListActivity.this.mAdapter.addData(WallpaperListActivity.this.listWallpaperBean);
              WallpaperListActivity.this.mAdapter.notifyDataSetChanged();
              WallpaperListActivity.this.lvList.onLoadMoreComplete();
              WallpaperListActivity.this.blDataTask = true;
              if (WallpaperListActivity.this.lvList.getIsNoMore())
              {
                WallpaperListActivity.this.lvList.hideFotterMoreView();
                WallpaperListActivity.this.lvList.setIsNoMore(true);
              }
              if (WallpaperListActivity.this.isFoot.booleanValue())
                break;
              WallpaperListActivity.this.closeProgress();
              WallpaperListActivity.this.isFoot = Boolean.valueOf(false);
              break;
              if (WallpaperListActivity.this.dbServerHaveMore)
              {
                WallpaperListActivity localWallpaperListActivity1 = WallpaperListActivity.this;
                localWallpaperListActivity1.pageServer = (1 + localWallpaperListActivity1.pageServer);
              }
            }
          }
          WallpaperListActivity.this.lvList.onLoadMoreComplete();
          WallpaperListActivity.this.blDataTask = true;
          WallpaperListActivity.this.lvList.hideFotterMoreView();
          WallpaperListActivity.this.lvList.setIsNoMore(true);
          if (!WallpaperListActivity.this.isFoot.booleanValue())
          {
            WallpaperListActivity.this.closeProgress();
            WallpaperListActivity.this.isFoot = Boolean.valueOf(false);
          }
        }
      }
    }

    protected void onPreExecute()
    {
      WallpaperListActivity.this.blDataTask = false;
      if (!WallpaperListActivity.this.isFoot.booleanValue())
        WallpaperListActivity.this.showProgress("");
      super.onPreExecute();
    }
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.activity.WallpaperListActivity
 * JD-Core Version:    0.6.2
 */